﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace SampleBenchmarks
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach (var benchmark in GetAllRunnableTypes())
                Run(benchmark);

            Console.WriteLine("Press ENTER to exit..");
            Console.ReadLine();
        }

        private static IEnumerable<Type> GetAllRunnableTypes()
        {
            return Assembly.GetExecutingAssembly().GetTypes()
                            .Where(type => type.GetInterfaces().Contains(typeof(Runnable)));
        }

        private static void Run(Type benchmark)
        {
            var runnableBM = (Activator.CreateInstance(benchmark) as Runnable);
            WriteHorizontalRuler();
            Console.WriteLine("Benchmark example: " + benchmark.Name.Replace('_', ' '));
            WriteHorizontalRuler();
            runnableBM.Run();
            Console.WriteLine();
        }
 
        private static void WriteHorizontalRuler()
        {
            Console.WriteLine(string.Empty.PadRight(Console.BufferWidth -2, '-'));
        }
    }
}